package com.chixing.controller;

import com.chixing.pojo.Customer;
import com.chixing.service.RegisterService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;

@Controller
public class RegisterController {
    @Autowired
    private RegisterService registerService;
    @PostMapping("register")
    @ResponseBody
    public ServerResponse add(Customer customer, HttpSession session){
//        System.out.println("密文1:"+customer.getCustPassword());
        String encrypted = customer.getCustPassword();

        ServerResponse serverResponse = registerService.register(customer);
        if(serverResponse.getCode()==200) {
            System.out.println("成功");
            return serverResponse;
        }
//        return ServerResponse.getSuccess("注册成功");
        else {
            System.out.println("失败");
        }
        return serverResponse;
    }

    @GetMapping("/publickey")
    @ResponseBody
    public ServerResponse resregister() {

        return registerService.getPublicKey();
    }
}
